<template>
  <div class="app-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>聊天用户管理</span>
        </div>
      </template>

      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column prop="id" label="ID" width="80" />
        <el-table-column prop="username" label="用户名" />
        <el-table-column prop="nickname" label="昵称" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag :type="scope.row.status === 'ONLINE' ? 'success' : 'info'">
              {{ scope.row.status === 'ONLINE' ? '在线' : '离线' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="lastActiveTime" label="最后活跃时间" width="180" />
        <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
          <template #default="scope">
            <div class="table-operation-wrapper">
              <el-button
                type="info"
                icon="View"
                @click="handleDetail(scope.row)"
                class="table-operation-button is-info"
                size="small"
              >详情</el-button>
              <el-button
                type="warning"
                icon="ChatDotRound"
                @click="handleMessage(scope.row)"
                class="table-operation-button is-warning"
                size="small"
              >发消息</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

const loading = ref(false)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)

const tableData = ref([
  {
    id: 1,
    username: 'user001',
    nickname: '张三',
    status: 'ONLINE',
    lastActiveTime: '2024-01-15 10:30:00'
  }
])

// 多选框选中数据
const handleSelectionChange = (selection) => {
  ids.value = selection.map(item => item.id)
  single.value = selection.length !== 1
  multiple.value = !selection.length
}

// 查看详情操作
const handleDetail = (row) => {
  console.log('查看用户详情:', row.id)
  ElMessage.info('查看用户详情功能')
}

// 发送消息操作
const handleMessage = (row) => {
  console.log('发送消息给用户:', row.id)
  ElMessage.info('发送消息功能')
}

onMounted(() => {
  // 初始化数据
})
</script>

<style lang="scss" scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
